package ro.gateway.aida.obj;

import java.util.Enumeration;
import java.util.Hashtable;


/**
 * <p>Title: Romanian AIDA</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (comparator) 2003</p>
 * <p>Company: ro-gateway</p>
 * @author Mihai Popoaei, mihai_popoaei@yahoo.com, smike@intellisource.ro
 * @version 1.0-* @version $Id: ActivityStatus.java,v 1.1 2004/10/24 23:37:10 mihaipostelnicu Exp $
 */
public class ActivityStatus extends LocalizedItem {
    private long id = -1;
    private long st_code = -1;
    private Hashtable statuses;
    private Hashtable descriptions;
    private LangString status;
    private LangString description;

    public ActivityStatus() {
        this.statuses = new Hashtable();
        this.descriptions = new Hashtable();
        status = new LangString();
        description = new LangString();
    }

    public String getDescription(String lang) {
        if (lang == null)
            return null;

        String result = (String) descriptions.get(lang);

        if (result == null) {
            String lng = "ro";

            if (descriptions.get(lng) == null) {
                lng = "en";

                if (descriptions.get(lng) == null) {
                    if (descriptions.keys().hasMoreElements())
                        lng = (String) descriptions.keys().nextElement();
                    else
                        lng = "unknown";
                }
            }

            String desc = (String) descriptions.get(lng);
            result = desc + " (" + lng + ")";
        }

        return result;
    }

    public String getStatus(String lang) {
        if (lang == null)
            return null;

        if (statuses.size() < 1)
            return null;

        String result = (String) statuses.get(lang);

        if (result == null) {
            String lng = "en";

            if (statuses.get(lng) == null) {
                lng = "ro";

                if (statuses.get(lng) == null)
                    lng = (String) statuses.keys().nextElement();
            }

            String desc = (String) statuses.get(lng);
            result = desc + " (" + lng + ")";
        }

        return result;
    }

    public long getSt_code() {
        return st_code;
    }

    public void setDescription(String lang, String description) {
        String status = (String) statuses.get(lang);

        if (status == null)
            throw new RuntimeException(
                "Can't set description::set status first");

        this.descriptions.put(lang, description);
        this.description.setString(lang, description);
    }

    public void setStatus(String lang, String status) {
        this.statuses.put(lang, status);
        this.status.setString(lang, status);
    }

    public void setSt_code(long st_code) {
        this.st_code = st_code;
    }

    public void setId(long id) {
        this.id = id;
    }

    public long getId() {
        return id;
    }

    public void clearDescriptions() {
        this.descriptions.clear();
        this.description.clear();
    }

    public void clearStatuses() {
        this.statuses.clear();
        this.status.clear();
    }

    public String[] getAvailableLangs() {
        if (statuses.size() < 1)
            return null;

        String[] result = new String[statuses.size()];
        Enumeration en = statuses.keys();
        int i = 0;

        while (en.hasMoreElements())
            result[i++] = (String) en.nextElement();

        return result;
    }

    /**
     * @return
     */
    public LangString getDescription() {
        return description;
    }

    /**
     * @return
     */
    public LangString getStatus() {
        return status;
    }

    /**
     * @param string
     */
    public void setDescription(LangString string) {
        description = string;
    }

    /**
     * @param string
     */
    public void setStatus(LangString string) {
        status = string;
    }
    
    public static final String LIST="Status_LIST";
}
